﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using System.Drawing;

namespace WebSys.UI.Control.ZhengShou
{
    public class CX_ZSBCJHZControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        DropDownList DropDownList1, DropDownList2;
        MPCalendar Calendar1, Calendar2;
        CustomGridView CustomGridList1;
        RadioButton RadioButton1, RadioButton2;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            if (!base.Page.IsPostBack)
            {
                Bind();
                QSDataDLL();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
            Button btnSeach = (Button)FindControl("btnSeach");
            btnSeach.Click += new EventHandler(btnSeach_Click);
        }
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void InitControl()
        {
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            DropDownList1 = (DropDownList)FindControl("DropDownList1");
            DropDownList2 = (DropDownList)FindControl("DropDownList2");
            Calendar1 = (MPCalendar)FindControl("Calendar1");
            Calendar2 = (MPCalendar)FindControl("Calendar2");
            RadioButton1 = (RadioButton)FindControl("RadioButton1");
            RadioButton2 = (RadioButton)FindControl("RadioButton2");
        }
        protected void Bind()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            DataTable dt = _EluZSDataProvider.GetZSBCJHZ(RadioButton1.Checked,RadioButton2.Checked,Calendar1.Text, Calendar2.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue,userid);
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.DataBind();
        }

        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }

        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //6：到账，7：划转，8：余额，9：需划转额度.
                EluZSProvider.YJCS yjcs = _EluZSDataProvider.GetYJCS();
                string strYED = yjcs.存在部分协议补偿款未支付;
                string strYEL = yjcs.到账余额已小于补偿额度;
                string temp = e.Row.Cells[6].Text.Trim();
                if (strYED == "1")
                {
                    string temp1 = e.Row.Cells[7].Text.Trim();
                    if (string.IsNullOrEmpty(temp) || temp == "&nbsp;") { temp = "0"; }
                    if (string.IsNullOrEmpty(temp1) || temp1 == "&nbsp;") { temp1 = "0"; }
                    double tt = Convert.ToDouble(temp);
                    double tt1 = Convert.ToDouble(temp1);
                    double tt2 = tt - tt1;
                    if (tt2 > 0)
                    {
                        for (int i = 0; i < e.Row.Cells.Count; i++)
                        {
                            e.Row.Cells[i].BackColor = Color.FromName("#FE6501");
                        }
                    }
                }
                if (strYEL == "1")
                {
                    string temp2 = e.Row.Cells[9].Text;
                    if (string.IsNullOrEmpty(temp) || temp == "&nbsp;") { temp = "0"; }
                    if (string.IsNullOrEmpty(temp2) || temp2 == "&nbsp;") { temp2 = "0"; }
                    double tt = Convert.ToDouble(temp);
                    double tt2 = Convert.ToDouble(temp2);
                    double tt3 = tt2 - tt;
                    if (tt3 > 0)
                    {
                        for (int i = 0; i < e.Row.Cells.Count; i++)
                        {
                            e.Row.Cells[i].BackColor = Color.FromName("Red");
                        }
                    }
                }
            }
        }

        protected void QSDataDLL()
        {
            //List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("区属");
            //EluZSProvider.Params item = new EluZSProvider.Params();
            //_params.Insert(0, item);
            DataTable dt = _EluZSDataProvider.GetParamYB("区属", GetSqlWhere());
            DropDownList1.DataSource = dt;
            DropDownList1.DataValueField = "keyvalue";
            DropDownList1.DataTextField = "keyname";
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "");
            List<EluZSProvider.Params> _params1 = _EluZSDataProvider.GetParams("房屋用途");
            EluZSProvider.Params item1 = new EluZSProvider.Params();
            _params1.Insert(0, item1);
            DropDownList2.DataSource = _params1;
            DropDownList2.DataValueField = "keyvalue";
            DropDownList2.DataTextField = "keyname";
            DropDownList2.DataBind();
        }


        protected string GetSqlWhere()
        {
            string sqlWhere = string.Empty;
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @" and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||keyname||'%' ";
            }
            return sqlWhere;
        }
    }
}


